package com.chuangke.system.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chuangke.common.http.HttpResult;

import cn.hutool.core.util.StrUtil;

@RestController
@RequestMapping("word")
public class SysWordAnalyse {

	@PreAuthorize("hasAuthority('login:action')")
	@GetMapping(value = "/analyse")
	public HttpResult Analyse(@RequestParam String word) {
		if (StrUtil.isBlank(word)) {
			return HttpResult.ok();
		}

		List<Word> words = WordSegmenter.segWithStopWords(word);

        List<String> result = new ArrayList<>(words.stream().map(Word::getText).collect(Collectors.toList()));
//		result.add(word);

		return HttpResult.ok(result);
	}
}
